package com.example.myapplication.ui.screens


import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.model.entity.NavigationItem
import com.google.accompanist.insets.ProvideWindowInsets
import com.google.accompanist.insets.navigationBarsPadding

@Composable
fun MainFarme(onNavigateToArticle: () -> Unit = {}, onNavigateToVideo: () -> Unit = {}) {
    val navigationItems = listOf<NavigationItem>(
        NavigationItem("学习", Icons.Filled.Home),
        NavigationItem("任务", Icons.Filled.DateRange),
        NavigationItem("我的", Icons.Filled.Person)
    )

    var select by remember {
        mutableStateOf(0)
    }

        Scaffold(bottomBar = {
            // 使用预制主题或颜色MaterialTheme.colors
            // alwaysShowLabel 默认不显示tabbar的文本
            // selectedContentColor 选中时颜色
            // unselectedContentColor 未选中时颜色
            BottomNavigation(backgroundColor = MaterialTheme.colors.surface, modifier = Modifier.navigationBarsPadding()) {
                navigationItems.forEachIndexed { index, navigationItem ->
                    BottomNavigationItem(
                        selected = index == select,
                        onClick = {
                            select = index
                        },
                        icon = { Icon(imageVector = navigationItem.icon, contentDescription = null) },
                        label = {
                            Text(text = "${navigationItem.title}")
                        },
                        alwaysShowLabel = false,
                        selectedContentColor = Color(0xFF87CEFF),
                        unselectedContentColor = Color(0xFF999999))
                }
            }
        }) {
            Box(modifier = Modifier.padding(it)) {
                when(select) {
                    0 -> StudyScreen(onNavigateToArticle = onNavigateToArticle, onNavigateToVideo = onNavigateToVideo)
                    1 -> Task()
                    2 -> My()
                }
            }
        }


}

@Preview
@Composable
fun MainFarmePreview() {
    MainFarme()
}

